package com.zhcd.sys.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhcd.sys.pojo.Manage;
import com.zhcd.sys.pojo.Patient;
import com.zhcd.sys.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author feifei
 * @since 2021-11-29
 */
@RestController
@RequestMapping("/sys/patient")
public class PatientController {
    @Autowired
    public PatientService patientService;

    //查询全部患者
    @RequestMapping(value = "/getAll_Patient",method = RequestMethod.GET)
    @ResponseBody
    public String getAll_Patient() throws JsonProcessingException {
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",patientService.getAll_Patient());
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }

    //按照条件(患者姓名、医院名称、科室名称、医生名称)查询患者
    @RequestMapping(value = "/getList_Patient",method = RequestMethod.GET)
    @ResponseBody
    public String getList_Patient(@RequestBody Map<String,Object> para) throws JsonProcessingException {
        String patientname=(String)para.get("patientname");
        String hospitalname=(String)para.get("hospitalname");
        String departmentname=(String)para.get("departmentname");
        String doctorname=(String)para.get("doctorname");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",patientService.getList_Patient(patientname,hospitalname,departmentname,doctorname));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
    //添加患者
    @RequestMapping(value = "/ins_Patient",method = RequestMethod.POST)
    @ResponseBody
    public String ins_Patient(@RequestBody Map<String,Object> para) throws JsonProcessingException {
        Patient patient=(Patient)para.get("doctorname");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",patientService.ins_Patient(patient));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }

    //删除患者信息
    @RequestMapping(value = "/del_Patient",method = RequestMethod.DELETE)
    @ResponseBody
    public String del_Patient(@RequestBody Map<String,Object> para) throws JsonProcessingException {
        Integer id=(Integer)para.get("id");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",patientService.del_Patient(id));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
}

